<template>
  <el-dialog
    class="constructionAdd"
    title="上传初支质量检测报告"
    :visible.sync="dialogVisible"
    width="60%"
    :before-close="handleClose"
  >
    <el-form :inline="true" ref="form" :model="form" label-width="150px" class="demo-form-inline">
      <el-row>
        <el-col :span="12">
          <el-form-item
            label="开始里程"
            :rules="[
      { required: true, message: '请输入开始里程', trigger: 'blur' }
    ]"
          >
            <el-input v-model="form.startMileage"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="结束里程"
            :rules="[
      { required: true, message: '请输入结束里程', trigger: 'blur' }
    ]"
          >
            <el-input v-model="form.endMileage"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item
            label="检测长度"
            :rules="[
      { required: true, message: '请输入检测长度', trigger: 'blur' }
    ]"
          >
            <el-input v-model="form.mileageLength"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="检测内容">
            <el-input v-model="form.mileageContext"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item
            label="检测结果"
            :rules="[
      { required: true, message: '请选择检测结果', trigger: 'blur' }
    ]"
          >
            <el-radio v-model="form.result" @click.native="chooseIdClick(1)" label="1">合格</el-radio>
            <el-radio v-model="form.result" @click.native="chooseIdClick(2)" label="2">不合格</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="showClass==true" label="不合格缘由">
            <el-input type="textarea" v-model="form.unqualified"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item
            label="报告编号"
            :rules="[
      { required: true, message: '请输入报告编号', trigger: 'blur' }
    ]"
          >
            <el-input v-model="form.reportNo"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="创建时间"
            :rules="[
      { required: true, message: '请输入创建时间', trigger: 'blur' }
    ]"
          >
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
              v-model="form.createTime"
              style="width: 100%;"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="初支厚度">
            <el-input v-model="form.chuThickness"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="初支背部密实状况">
            <el-input v-model="form.chuHollow"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="钢拱架间距">
            <el-input v-model="form.chuSpacing"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="锚杆拉拔力">
            <el-input v-model="form.chuForce"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="锚杆长度及密实度">
            <el-input v-model="form.chuBoltlength"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="断面轮廓">
            <el-input v-model="form.chuProfile"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="仰拱厚度">
            <el-input v-model="form.chuInvertThickness"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="检测报告">
            <el-upload
              name="file"
              class="upload-demo"
              action="string"
              :http-request="beforeAvatarUploadThree"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="3"
              :on-success="handlesuccess"
              :on-error="handleerror"
              :on-exceed="handleExceed"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from "../../../api";
import qs from "qs";

export default {
  data() {
    return {
      showClass: false,
      dialogVisible: false,
      tunnelList: [],
      form: {
        wId: "",
        testType: "初支检测",
        startMileage: "",
        endMileage: "",
        mileageLength: "",
        mileageContext:
          "1、初期支护厚度2、初期支护背部密实状况3、钢拱架间距4、锚杆拉拔力5、锚杆长度及注浆密实度6、断面轮廓7、仰拱（二次衬砌及回填层）总厚度",
        createTime: "",
        resources: "",
        result: "",
        reportNo: "",
        unqualified: "", //不合格理由
        chuThickness: "", //初支厚度
        chuHollow: "", //初支背部密实状况
        chuSpacing: "", //钢拱架间距
        chuForce: "", //锚杆拉拔力
        chuBoltlength: "", //锚杆长度及密实度
        chuProfile: "", //断面轮廓
        chuInvertThickness: "", //仰拱厚度
      },
      fileList: [],
    };
  },
  mounted() {
    this.$bus.$on("onAddQuailtyWid", (flag) => {
      this.form.wId = flag;
    });
    this.$bus.$on("onAddQuailtyShow", (flag) => {
      if (this.form.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        this.dialogVisible = false;
      } else {
        this.dialogVisible = flag;
      }
    });
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    create() {
      if (this.form.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        return;
      }
      api
        .monitorMeasuresave(qs.stringify(this.form))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: "success",
              message: "添加成功!",
            });
            this.dialogVisible = false;
            this.$bus.$emit("onRefreshQuailtyAdmin", {wid: this.form.wId});
          } else {
            this.$message({
              type: "fail",
              message: res.data.message,
            });
          }
        })
        .catch((err) => {});
    },
    handlesuccess(response, file, fileList) {
      console.log(response);
      if (response.code == 2001) {
        this.form.resources = response.data;
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleerror(err, file, fileList) {
      console.log(err);
    },
    beforeAvatarUploadThree(file) {
      let params = new FormData();
      params.append("file", file.file);
      api
        .AddrPlaneFileUpload(params)
        .then((res) => {
          if (res.data.code == 2001) {
            this.form.resources = res.data.data;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleCurrentChange(v) {},
    chooseIdClick(val) {
      if (val == 1) {
        this.showClass = false;
      } else {
        this.showClass = true;
      }
    },
  },
};
</script>

<style scoped>
.avatar-uploader .el-upload {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  width: 50px !important;
  height: 50px !important;
  font-size: 28px;
  line-height: 50px !important;
  color: #8c939d;
  text-align: center;
}
.avatar {
  display: block;
  width: 50px !important;
  height: 50px !important;
}
.imgbeforepad {
  padding-top: 0px !important;
}
.avatar-uploader .el-icon-plus {
  margin: 15px !important;
}

.constructionAdd :deep(.el-input--suffix .el-input__inner) {
  width: 202px;
}
.constructionAdd :deep(.el-textarea__inner) {
  width: 202px;
}
.constructionAdd :deep(.el-form--inline .el-form-item__content) {
  width: 202px;
}
</style>